﻿# coding: utf-8

import wx
import wx.lib.filebrowsebutton as filebrowse
import wx.lib.agw.labelbook as LB

class wxPanelGSGeneral(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, style = wx.BORDER_STATIC)
       
        self._dbbWorkDir = filebrowse.DirBrowseButton(
            self, -1, changeCallback = self.__OnWorkingDirectoryChanged,
            labelText = TD.WORKING_DIRECTORY,
            buttonText = TD.BUTTON_BROWSE,
            startDirectory = GLOBAL_SETTING._general._workDir)
            
        self._dbbWorkDir.SetValue(GLOBAL_SETTING._general._workDir)
            
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self._dbbWorkDir, 0, wx.EXPAND|wx.ALL, border = 10)
        sizer.AddStretchSpacer()
        self.SetSizer(sizer)
            
    def __OnWorkingDirectoryChanged(self, e):
        v = self._dbbWorkDir.GetValue()
        if not v.endswith('\\'):
            v += '\\'
        GLOBAL_SETTING._general._workDir = v
        
class wxDialogGlobalSetting(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, -1, title = TD.DIALOG_GLOBAL_SETTING, size = (800, 480), 
            style = wx.CAPTION|wx.RESIZE_BORDER)
        
        self.Center()
        
        # Create note book.
        self._book = LB.FlatImageBook(self, -1, style = LB.INB_LEFT)
        
        self._imageList = wx.ImageList(32, 32)
        self._imageList.Add(IL.GetBitmap(IL.ID_IMAGE_MESH, IL.IMAGE_BIG))
        
        self._book.AssignImageList(self._imageList)
        
        self._book.AddPage(wxPanelGSGeneral(self._book), 'test', True, 0)
            
        # Layout
        ok = wx.Button(self, wx.ID_OK, TD.BUTTON_OK)
        cancel = wx.Button(self, wx.ID_CANCEL, TD.BUTTON_CANCEL)
        apply = wx.Button(self, wx.ID_APPLY, TD.BUTTON_APPLY)
        
        sizer1 = wx.BoxSizer(wx.HORIZONTAL)
        sizer1.AddStretchSpacer()
        sizer1.Add(ok, 0, wx.EXPAND|wx.ALL, border = 5)
        sizer1.Add(cancel, 0, wx.EXPAND|wx.ALL, border = 5)
        sizer1.Add(apply, 0, wx.EXPAND|wx.ALL, border = 5)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self._book, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border = 10)
        sizer.Add(sizer1, 0, wx.EXPAND|wx.TOP, border = 10)
        
        self.SetSizer(sizer)
        
        # Bind events
        self.Bind(wx.EVT_BUTTON, self.__OnCmdOk, ok)
        self.Bind(wx.EVT_BUTTON, self.__OnCmdCancel, cancel)
        self.Bind(wx.EVT_BUTTON, self.__OnCmdApply, apply)
        
    def __OnCmdOk(self, e):
        GLOBAL_SETTING.Save()
        GLOBAL_SETTING.Apply()
        e.Skip()
        
    def __OnCmdCancel(self, e):
        GLOBAL_SETTING.Load()
        self.Close()
        e.Skip()
        
    def __OnCmdApply(self, e):
        GLOBAL_SETTING.Save()
        GLOBAL_SETTING.Apply()
        
        
        